<template>
    <svg :class="svgClass + ' ' + iconClass" aria-hidden="true" v-if="this.$icons.indexOf(iconClass) !== -1">
        <use :xlink:href="iconName"></use>
    </svg>
    <div :class="iconClass" v-else></div>
</template>

<script>
    export default {
        name: "svg-icon",
        props: {
            iconClass: {
                type: String,
                required: true
            },
            className: {
                type: String,
                default: ""
            }
        },
        computed: {
            iconName() {
                return `#${this.iconClass}`;
            },
            svgClass() {
                if (this.className) {
                    return "icon-svg " + this.className;
                } else {
                    return "icon-svg";
                }
            }
        }
    };
</script>

<style scoped>
    .icon-svg {
        width: 1em;
        height: 1em;
        vertical-align: -.15em;
        fill: currentColor;
        overflow: hidden;
    }
</style>
